<template>
  <a-card :bordered="false">
    <!-- table区域-begin -->
    <div>
      <vxe-grid
        style="width: 100%;"
        :height="curHeight"
        size="mini"
        align="center"
        highlight-hover-row
        stripe
        row-key
        row-id="selectedRowKeys"
        column-min-width="150"
        id="id"
        keep-source
        :loading="loading"
        border
        resizable
        auto-resize
        showOverflow
        showHeaderOverflow
        :pager-config="tablePage"
        ref="xGrid"
        :row-config="{ useKey: true,keyField: 'id',isCurrent:true,isHover:true}"
        :checkbox-config="{
          checkRowKeys:selectedRowKeys,
          trigger: 'row',
          highlight: true,
          reserve: true}"
        @sort-change="sortChange"
        @checkbox-change="checkboxChangeEvent"
        @checkbox-all="checkboxChangeEvent"
        :data="dataSource"
        :columns="columns"
        @page-change="handlePageChange"
      >
        <template v-slot:top>
          <div class="table-operator">
            <a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>
            <!-- 高级查询区域 -->
            <j-super-query :fieldList="superFieldList" ref="superQueryModal"
                           @handleSuperQuery="handleSuperQuery"></j-super-query>
            <a-dropdown v-if="selectedRowKeys.length > 0">
              <a-menu slot="overlay">
                <a-menu-item key="1" @click="allocate">
                  <a-icon type="edit"/>
                  分配
                </a-menu-item>
                <a-menu-item key="1" @click="dispatch">
                  <a-icon type="edit"/>
                  分发
                </a-menu-item>
              </a-menu>
              <a-button type="primary" icon="down">批量操作</a-button>
            </a-dropdown>
          </div>
        </template>
        <template v-slot:operate="{ row }">
          <a-button v-if="row.asnStatus != 2" type="primary" shape="circle" @click="handleEdit(row)" icon="edit"/>
          <a-button v-else type="primary" shape="circle" @click="handleEdit(row)" icon="edit" disabled/>
          <a-divider type="vertical"/>
          <a-dropdown>
            <a-button type="primary" shape="circle" class="ant-dropdown-link" icon="setting"/>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(row)">详情</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </template>
        <template v-slot:empty>
          <a-empty/>
        </template>
      </vxe-grid>
    </div>
    <wms-pick-order-modal ref="modalForm" @ok="modalFormOk"></wms-pick-order-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {HYListMixin} from '@/mixins/HYListMixin'
import WmsPickOrderModal from './modules/WmsPickOrderModal'
import {postAction} from "@api/manage";

export default {
  name: 'WmsPickOrderList',
  mixins: [HYListMixin, mixinDevice],
  components: {
    WmsPickOrderModal
  },
  data() {
    return {
      description: '出库单管理页面',
      isorter: {
        column: 'pk.createTime',
        order: 'desc',
      },
      // 表头
      columns: [
        {type: "checkbox", width: 50, align: "center"},//多选
        {type: "seq", width: 50, align: "center"},//
        {title: '单据编码', align: "center", field: 'code'},
        {title: '外部单号', align: "center", field: 'outerNo'},
        {title: '订单类型', align: "center", field: 'orderType_dictText'},
        {title: '订单状态', align: "center", field: 'orderStatus_dictText'},
        {title: '分配状态', align: "center", field: 'allocateStatus_dictText'},
        {title: '发货状态', align: "center", field: 'shipStatus_dictText'},
        {title: '过账状态', align: "center", field: 'syncStatus_dictText'},
        {title: '订单时间', align: "center", field: 'orderDate'},
        {title: '总数量', align: "center", field: 'demonQty'},
        {title: '分配数量', align: "center", field: 'allocateQty'},
        {title: '拣货数量', align: "center", field: 'pickedQty'},
        {title: '发货数量', align: "center", field: 'shipQty'},
        {title: '备货库位', align: "center", field: 'shipLocationCode'},
        {title: '创建人', align: "center", field: 'createBy'},
        {title: '创建日期', align: "center", width: 200, field: 'createTime'},
        {title: '更新人', align: "center", field: 'updateBy'},
        {title: '更新日期', align: "center", width: 200, field: 'updateTime'},
        {title: '操作', fixed: 'right', width: 105, slots: {default: 'operate'}}
      ],
      url: {
        list: "/wms/wmsPickOrder/list",
        allocateUrl: "/wms/wmsPickOrder/allocate",
        dispatchUrl: "/wms/wmsPickOrder/dispatch",
        delete: "/wms/wmsPickOrder/delete",
        deleteBatch: "/wms/wmsPickOrder/deleteBatch",
        exportXlsUrl: "/wms/wmsPickOrder/exportXls",
        importExcelUrl: "wms/wmsPickOrder/importExcel",
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    allocate() {
      var that = this;
      that.loading = true;
      let params = new URLSearchParams();
      params.append('pkIds', that.selectedRowKeys);
      postAction(that.url.allocateUrl, params).then((res) => {
        if (res.success) {
          that.$message.success(res.message);
        } else {
          that.$message.warning(res.message);
        }
      }).finally(() => {
        that.loading = false;
        that.modalFormOk();
      })
    },
    dispatch() {
      var that = this;
      that.loading = true;
      let params = new URLSearchParams();
      params.append('pkIds', that.selectedRowKeys);
      postAction(that.url.dispatchUrl, params).then((res) => {
        if (res.success) {
          that.$message.success(res.message);
        } else {
          that.$message.warning(res.message);
        }
      }).finally(() => {
        that.loading = false;
        that.modalFormOk();
      })
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({type: 'string', value: 'orderType', text: '订单类型', dictCode: ''})
      fieldList.push({type: 'string', value: 'code', text: '单据编码', dictCode: ''})
      fieldList.push({type: 'string', value: 'outerNo', text: '外部单号', dictCode: ''})
      fieldList.push({type: 'int', value: 'orderStatus', text: '单据状态', dictCode: ''})
      fieldList.push({type: 'datetime', value: 'orderDate', text: '订单时间'})
      fieldList.push({type: 'string', value: 'shipLocationId', text: '备货库位', dictCode: ''})
      fieldList.push({type: 'int', value: 'syncStatus', text: '过账状态', dictCode: ''})
      fieldList.push({type: 'int', value: 'allocateStatus', text: '分配状态', dictCode: ''})
      fieldList.push({type: 'int', value: 'pickStatus', text: '拣货状态', dictCode: ''})
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>